ChatFrame1:AddMessage("\124cFF1987FFHex\124cFFFFFFFFRepair Loaded.")
local filter = {
	[60842] = false, -- Fortune Card. (Green 20g)
	[60843] = false, -- Fortune Card. (Blue 50g)
	[62606] = false, -- Fortune Card. (Blue 50g)
	[60845] = false, -- Fortune Card. (Blue 200g)
	[60840] = false, -- Fortune Card. (Epic 1000g)
	[60844] = false, -- Fortune Card. (Epic 5000g)
	[62576] = true, -- Fortune Card.
	[62575] = true, -- Fortune Card.
	[62574] = true, -- Fortune Card.
	[62573] = true, -- Fortune Card.
	[62572] = true, -- Fortune Card.
	[62571] = true, -- Fortune Card.
	[62570] = true, -- Fortune Card.
	[62569] = true, -- Fortune Card.
	[62568] = true, -- Fortune Card.
	[62567] = true, -- Fortune Card.
	[62566] = true, -- Fortune Card.
	[62565] = true, -- Fortune Card.
	[62564] = true, -- Fortune Card.
	[62563] = true, -- Fortune Card.
	[62562] = true, -- Fortune Card.
	[62561] = true, -- Fortune Card.
	[62560] = true, -- Fortune Card.
	[62559] = true, -- Fortune Card.
	[62558] = true, -- Fortune Card.
	[62557] = true, -- Fortune Card.
	[62556] = true, -- Fortune Card.
	[62555] = true, -- Fortune Card.
	[62554] = true, -- Fortune Card.
	[62553] = true, -- Fortune Card.
	[62552] = true, -- Fortune Card.
	[62551] = true, -- Fortune Card.
	[62550] = true, -- Fortune Card.
	[62549] = true, -- Fortune Card.
	[62548] = true, -- Fortune Card.
	[62547] = true, -- Fortune Card.
	[62591] = true, -- Fortune Card.
	[62246] = true, -- Fortune Card.
	[62577] = true, -- Fortune Card.
	[62578] = true, -- Fortune Card.
	[62579] = true, -- Fortune Card.
	[62580] = true, -- Fortune Card.
	[62581] = true, -- Fortune Card. 
	[62582] = true, -- Fortune Card.
	[62583] = true, -- Fortune Card.
	[62584] = true, -- Fortune Card.
	[62585] = true, -- Fortune Card.
	[62586] = true, -- Fortune Card.
	[62587] = true, -- Fortune Card.
	[62588] = true, -- Fortune Card.
	[62589] = true, -- Fortune Card.
	[62590] = true, -- Fortune Card.
	[60839] = true, -- Fortune Card.
	[62598] = true, -- Fortune Card.
	[62599] = true, -- Fortune Card.
	[62600] = true, -- Fortune Card.
	[62601] = true, -- Fortune Card.
	[62605] = true, -- Fortune Card.
	[62604] = true, -- Fortune Card.
	[62603] = true, -- Fortune Card.
	[62602] = true, -- Fortune Card.
	[60841] = true, -- Fortune Card.
	[62247] = true, -- Fortune Card.
}

local AutoRepairSell = CreateFrame("Frame")
AutoRepairSell:RegisterEvent("MERCHANT_SHOW")
AutoRepairSell:SetScript("OnEvent", function()
	-- set static for now till we have UI
	-- local HexUI.config.autorepairsell = "true"
	--	if HexUI.config.autorepairsell == true then

	local c = 0
	for b=0,4 do
		for s=1,GetContainerNumSlots(b) do
			local l, lid = GetContainerItemLink(b, s), GetContainerItemID(b, s)
			if l and lid then
				local p = select(11, GetItemInfo(l))*select(2, GetContainerItemInfo(b, s))
				if select(3, GetItemInfo(l))==0 then
					UseContainerItem(b, s)
					PickupMerchantItem()
					c = c+p
				end
			end
		end
	end

	if c>0 then
		local g, s, c = math.floor(c/10000) or 0, math.floor((c%10000)/100) or 0, c%100
		print("Your Grey Items Have Been Sold For".." |cffffffff"..g.."|cffffd700g|r".." |cffffffff"..s.."|cffc7c7cfs|r".." |cffffffff"..c.."|cffeda55fc|r"..".")
	else
		print("\124cFF1987FFNothing to sell or repair!\124cFFFFFFFF You must be browsing...")
	end

	if CanMerchantRepair() then
		cost, possible = GetRepairAllCost()
		if cost>0 then
			if possible then
				-- see if the guild will foot the bill....
				if CanGuildBankRepair() then 
					ChatFrame1:AddMessage("The \124cFF1987FFGuild\124cFFFFFFFF covered this for you...") 
					RepairAllItems(1)
					local c = cost%100
					local s = math.floor((cost%10000)/100)
					local g = math.floor(cost/10000)
					print("Your Items Have Been Repaired For".." |cffffffff"..g.."|cffffd700g|r".." |cffffffff"..s.."|cffc7c7cfs|r".." |cffffffff"..c.."|cffeda55fc|r"..".")
				else
					ChatFrame1:AddMessage("You have to foot the \124cFF1987FFBill your self\124cFFFFFFFF...") 
					RepairAllItems(0)
					local c = cost%100
					local s = math.floor((cost%10000)/100)
					local g = math.floor(cost/10000)
					print("Your Items Have Been Repaired For".." |cffffffff"..g.."|cffffd700g|r".." |cffffffff"..s.."|cffc7c7cfs|r".." |cffffffff"..c.."|cffeda55fc|r"..".")
				end
			end
		end
	end
	-- end
end)